/*
htop - CpuThermalTempMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.

This meter written by coolflyreg (coolflyreg@gmail.com).
*/

#include "CpuThermalTempMeter.h"

#include <math.h>

#include "CRT.h"
#include "Object.h"
#include "Platform.h"
#include "XUtils.h"



static const int CpuThermalTempMeter_attributes[] = {
   CPU_THERMAL_TEMP
};

static void CpuThermalTempMeter_updateValues(Meter* this) {
   int temp = Platform_getCpuThermalTemp();
   if (temp == -1) {
      this->values[0] = NAN;
      xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "N/A");
      return;
   }


   this->values[0] = (double)temp / 1000.0;

   xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.1f%sC", this->values[0], CRT_degreeSign);

}

const MeterClass CpuThermalTempMeter_class = {
   .super = {
      .extends = Class(Meter),
      .delete = Meter_delete
   },
   .updateValues = CpuThermalTempMeter_updateValues,
   .defaultMode = TEXT_METERMODE,
   .maxItems = 1,
   .total = 100.0,
   .attributes = CpuThermalTempMeter_attributes,
   .name = "CPUThermalTemp",
   .uiName = "CPU Thermal Temp",
   .caption = "CPU Temp: ",
};
